/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rundata;

import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 *
 * @author mani
 */
public class XmlConfigureation {

    private Document read;
    private HashMap<String, String> hmss;

    public XmlConfigureation(String file) throws DocumentException {
        hmss = new HashMap<String, String>();
        SAXReader xmlReader = new SAXReader();
        read = xmlReader.read(new File( file));
        ParseAllConfiguration(read.getRootElement());
    }

    private void ParseAllConfiguration(Element rootElement) {
        Iterator elementIterator = rootElement.elementIterator();
        while (elementIterator.hasNext()) {
            Element next = (Element) elementIterator.next();
            String put = hmss.put(next.getName(), next.attributeValue("att"));
        }
    }

    String getConfigurationValue(String string) throws Exception {
        String get = hmss.get(string);
        if (get == null) {
            throw new Exception(string);
        }
        return get;
    }
}
